package com.jz.community.moduleshopping.orderDetail.task;

import android.app.Activity;

import com.jz.community.basecomm.constant.Constant;
import com.jz.community.basecomm.net.OkHttpUtil;
import com.jz.community.basecomm.task.ITaskCallbackListener;
import com.jz.community.basecomm.task.RxTask;
import com.jz.community.basecomm.utils.JsonUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.commview.view.widget.ProgressDialogManager;
import com.jz.community.moduleshopping.orderDetail.bean.OrderDetailBean;

import java.util.HashMap;

/**
 * Created by Target on 2018/4/6.
 */

public class OrderDetailTask extends RxTask<String, Integer, OrderDetailBean> {

    private Activity activity;
    private ITaskCallbackListener taskListener;

    public OrderDetailTask(Activity activity,
                           ITaskCallbackListener taskListener) {
        super(activity);
        this.activity = activity;
        this.taskListener = taskListener;
    }

    @Override
    protected OrderDetailBean doInBackground(String... params) {
        // 执行请求
        String result = OkHttpUtil.get(Constant.ORDER_DETAIL_URL + params[0], new HashMap<>());
        OrderDetailBean info = null;
        if (!Preconditions.isNullOrEmpty(result)) {
            info = JsonUtils.parseObject(result, OrderDetailBean.class);
        }
        return info;
    }

    @Override
    protected void onPostExecute(OrderDetailBean result) {
        // 执行结果回调函数
        taskListener.doTaskComplete(result);
        ProgressDialogManager.dismissProgressDialog();
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        ProgressDialogManager.showDialog(activity);
        super.onPreExecute();
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
    }

}
